﻿using IceZero.Business.Business;
using IceZero.DataStore;
using System.Linq;

namespace Microsoft.Extensions.DependencyInjection
{
    public static class IceZeroWebExtensions
    {
        public static IServiceCollection AddIceZeroWeb(this IServiceCollection services)
        {
            //注入通用的 datastore
            var dsAssembly = typeof(AppConfigDataStore).Assembly;
            var dataStores = dsAssembly.GetTypes().Where(t => t.Name.EndsWith("DataStore")).ToList();
            foreach (var ds in dataStores)
            {
                services.AddScoped(ds);
            }
            //注入通用的 business
            var bAssembly = typeof(AppConfigBusiness).Assembly;
            var business = bAssembly.GetTypes().Where(t => t.Name.EndsWith("Business")).ToList();
            foreach (var b in business)
            {
                services.AddScoped(b);
            }
            return services;
        }
    }
}
